# 创建列表
list_data <- list("Red","Green",c(21,32,11),21.53,119.1);
print(list_data);

# 命名列表元素
list_data <- list(c("Jan","Feb","Mar"),matrix(c(3,9,5,-1,-2,8),nrow=2),list("green",12.3));
print( list_data ); 

#对列表进行命名
names(list_data) <- c("1st Quarter", "A_Matrix", "A Inner list")

# 通过命名访问列表元素
print( list_data$A_Matrix)

# 通过索引访问列表元素
print( list_data[1]);

#对列表进行操作( 添加元素 )
list_data[4] <- "New element";
cat("Add new element","
    ");
print( list_data );

#删除元素
list_data[1] <- NULL;
cat("Delete element","
    ");
print( list_data );

#更新元素
list_data[3] <- "update element";
cat("Update element","
    ");
print( list_data );

#合并列表
list_one <- list(1,2,3);
list_two <- list("first","second","three");
merged.list <- c(list_one,list_two );
cat("merge list","
    ");
print( merged.list );

#将列表转换成向量 unlist()
list1<-list(1:5);
print( list1 );

list2<-list(10:14);
print( list2) ;

v1<- unlist( list1 );
print( v1 );

v2 <- unlist( list2 );
print( v2 );

